class smx_download  {

  require smx_os

  Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ] }

  if $fqdn =~ /^[a-z0-9]+\.[a-z0-9-]+\.foxitcloud\.com/ {
    $branch = 'develop'
    notify { "branch develop $fqdn": }
  }
  else {
    $branch = 'master'
    notify { "branch master $fqdn": }
  }

  file { '/vagrant/vagrant/download_files.sh':
    ensure => present,
    mode   => '0755',
    #    owner => root, group => root,
    source =>  "puppet:///modules/smx_download/download_files.sh",
  }

  exec { 'download_files':
    cwd       => '/vagrant/vagrant',
    command   => "/vagrant/vagrant/download_files.sh $branch",
    timeout   => '1800', # half an hour, at most
    logoutput => true,
    require   => File['/vagrant/vagrant/download_files.sh'],
  }

  file { ['/usr/share/tomcat','/usr/share/tomcat/latest','/usr/share/tomcat/latest/temp','/usr/share/tomcat/latest/temp/v2']:
    ensure => 'directory',
    before => Exec['download_files']
  }
}
